﻿Imports YvanSoftware.Orb
Imports YvanSoftware.Orb.Gui
Module Module1

    Dim strApiKey As String

    Sub Main()
        Try
            Dim strSessionID As String
            Console.WriteLine("OrbDotNet - GUI Test.")
            Console.WriteLine("---------------------")
            Console.WriteLine("Attempting to read API key.")
            strApiKey = InputBox("Please enter your API key.")
            If strApiKey = "" Then
                Throw New OrbNoApiKeyException

            End If
            Console.WriteLine("API Key read.")
            Console.WriteLine("Attempting logon.")
            Dim objGui As New PrebuildDialogs
            strSessionID = objGui.AskForLogin(strApiKey)

            If Len(strSessionID) < 1 Then
                Throw New OrbNoSessionIdFailure

            End If

            Dim oFrm As New frmPlayBack

            oFrm.oSP.SessionID = strSessionID
            oFrm.oSP.ApiKey = strApiKey

            Dim oStream As New Streaming(strApiKey, strSessionID)

            oStream.RetrieveChannels()
again:

            Console.WriteLine(vbCrLf & vbCrLf & vbCrLf & "Choose your stream:")
            Console.WriteLine("------------------------")
            Console.WriteLine("Make your choice by typing the number of the channel and press enter.")

            Dim intTeller As Integer

            For intTeller = 1 To oStream.lastChannel
                Console.WriteLine(intTeller & ") " & oStream.GetChannel(intTeller).Text)

            Next
            intTeller = Console.ReadLine
            If intTeller < 1 Or intTeller > oStream.lastChannel Then
                GoTo Again
            Else
                oFrm.oSP.PlayStream(oStream.GetChannel(intTeller).Value)
                oFrm.ShowDialog()

            End If

            Console.WriteLine("Example finished. Press any key to exit.")
            Console.ReadKey()
        Catch ex As OrbBaseException
            Dim oGui As New PrebuildDialogs
            oGui.Fatal(ex.Message & vbCrLf & ex.ExtraInfo)
        End Try
    End Sub

End Module
